import { View } from "../../../../mvc/core/View";
import { CopyGradeRollLabel } from "./CopyGradeRollLabel";
import { LayerManager } from "../../../manager/LayerManager";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { ItemCellRenderer } from "../kingCopy/itemRender/ItemCellRenderer";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { TodayNoTipsConst } from "../../../../component/gconst/TodayNoTipsConst";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { SWFInfo } from "../../../../../com/gengine/resource/info/SWFInfo";
import { SCopyMsgInfo } from "../../../../../Message/Public/SCopyMsgInfo";
import { ECopyInfoType } from "../../../../../Message/Public/ECopyInfoType";
import { CopyConfig } from "../../../resource/CopyConfig";
import { CopyMarkLevelConfig } from "../../../resource/CopyMarkLevelConfig";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { KingCopyItemView } from "../kingCopy/KingCopyItemView";
import { ECopyType } from "../../../../../Message/Public/ECopyType";
import { Global } from "../../../../../com/gengine/global/Global";
import { Cache } from "../../../cache/Cache";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class CopyGradeAccountView
    
    export  class CopyGradeAccountView extends View
    {
        constructor(arg1: int)
        {
            super();
            this._labelVec = new Vector.<CopyGradeRollLabel>();
            this.layer = LayerManager.windowLayer;
            this._sex = arg1;
            this.createChildren();
            this.mouseChildren = true;
            this.mouseEnabled = false;
            return;
        }

        /* internal  */removeBreakText(): void
        {
            if (this._textBm) 
            {
                if (this._textBm.parent) 
                {
                    this.removeChild(this._textBm);
                }
                this._textBm = null;
            }
            return;
        }

        protected createChildren(): void
        {
            this.loadResource();
            this._label1 = ObjCreate.createLabel(Language.getString(60044), 220, 166, 100, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this._label1.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 14, 16776960));
            this._label1.mouseChildren = false;
            this._label1.mouseEnabled = false;
            this._label2 = ObjCreate.createLabel(Language.getString(60045), 220, 235, 100, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this._label2.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 14, 16776960));
            this._label2.mouseChildren = false;
            this._label2.mouseEnabled = false;
            this.initScoreLabels();
            this._closeBtn = ObjCreate.createGButton("", 620, 110, 19, 19, this, "CloseButton");
            this._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCloseBtnClick);
            this._checkBox = ObjCreate.createCheckBox(Language.getString(69909), 220, 373, 120, 20, this, "GCheckBox2");
            this._checkBox.textField.filters = [FilterConst.glowFilter];
            this._checkBox.addEventListener(flash.events.Event.CHANGE, this.onCheckBoxChange);
            this._rewardList = ObjCreate.createTileList(220, 190, 230, 120, this);
            this._rewardList.scrollPolicy = ScrollPolicy.OFF;
            this._rewardList.columnWidth = 41;
            this._rewardList.rowHeight = 41;
            this._rewardList.setStyle("cellRenderer", ItemCellRenderer);
            this._bestPic = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this._bestPic, 217, 260, -1, -1, this);
            this._getRewardBtn = ObjCreate.createGButton(Language.getString(27904), 325, 270, 70, 28, this, "ButtonRed");
            this._getRewardBtn.addEventListener(flash.events.MouseEvent.CLICK, this.getRewardHandler);
            return;
        }

        /* internal  */onCloseBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */getRewardHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=this._rewardList.dataProvider;
            var loc4=0;
            if (loc1) 
            {
                while (loc4 < loc1.length) 
                {
                    loc2 = this._rewardList.itemToCellRenderer(loc1.getItemAt(loc4)) as ItemCellRenderer;
                    if (loc2 && loc2.item) 
                    {
                        loc3 = this._rewardList.localToGlobal(new Object /* flash.geom.Point */(loc2.x, loc2.y));
                        FlyToNavbarTool.flyToBackPack(loc2.item.bitmapdata, loc3);
                    }
                    ++loc4;
                }
            }
            this.hide();
            return;
        }

        /* internal  */onCheckBoxChange(arg1: Object /* flash.events.Event */): void
        {
            PulseSharedObject.save(TodayNoTipsConst.CopyGradeAccountTodayNoTips, this._checkBox.selected);
            return;
        }

        /* internal  */initScoreLabels(): void
        {
            this._labelNum = this.createRollLabel(CopyGradeRollLabel.Number, 220, 190);
            this._labelExp = this.createRollLabel(CopyGradeRollLabel.Number, 350, 190);
            this._labelTime = this.createRollLabel(CopyGradeRollLabel.Time, 480, 190);
            this._labelProgress = this.createRollLabel(CopyGradeRollLabel.Number, 220, 211);
            this._labelRing = this.createRollLabel(CopyGradeRollLabel.Number, 350, 211);
            this._labelCoin = this.createRollLabel(CopyGradeRollLabel.Number, 480, 211);
            this._labelScore = this.createRollLabel(CopyGradeRollLabel.Number, 220, 260);
            this._labelScore.labelFilters = [];
            return;
        }

        /* internal  */createRollLabel(arg1: string, arg2: int, arg3: int): CopyGradeRollLabel
        {
            var loc1=null;
            (loc1 = new CopyGradeRollLabel(arg1)).x = arg2;
            loc1.y = arg3;
            loc1.mouseChildren = false;
            loc1.mouseEnabled = false;
            this.addChild(loc1);
            this._labelVec.push(loc1);
            return loc1;
        }

        /* internal  */loadResource(): void
        {
            LoaderManager.instance.load("CopyGrade_sex" + this._sex + ".swf", this.onBgLoaded);
            return;
        }

        /* internal  */onBgLoaded(arg1: SWFInfo): void
        {
            arg1.clip.mouseChildren = false;
            arg1.clip.mouseEnabled = false;
            this.addChildAt(arg1.clip, 0);
            return;
        }

        public updateInfo(arg1: SCopyMsgInfo): void
        {
            var loc1=null;
            var loc2=null;
            this._info = arg1;
            this.reset();
            if (this._info.type.value() != ECopyInfoType._ECopyInfoTypeMarkEx) 
            {
                this.isCommonCopy = true;
                this.copy = CopyConfig.instance.getInfoByCode(arg1.num8);
                if (!this._timer) 
                {
                    this._timer = new Object /* flash.utils.Timer */(300, 20);
                    this._timer.addEventListener(flash.events.TimerEvent.TIMER, this.onTimerEvent);
                }
                this._timer.reset();
                this._timer.start();
            }
            else 
            {
                this.isCommonCopy = false;
                this.copy = CopyConfig.instance.getInfoByCode(arg1.num3);
                loc1 = CopyMarkLevelConfig.instance.getKingCopyRewards(arg1.num3, arg1.num1);
                loc2 = CopyMarkLevelConfig.instance.getItemByCodeAndLevel(arg1.num3, arg1.num1);
                if (loc2) 
                {
                    this._rewardList.dataProvider = new DataProvider(loc1);
                    this._rewardList.drawNow();
                    this._bestPic.bitmapData = GlobalClass.getBitmapData(KingCopyItemView.LEVEL_NAME + loc2.markLevel);
                    LoaderManager.instance.load("copyGradeLevel_" + loc2.markName + ".swf", this.onLevelSwfLoaded);
                    if (this._info.num4 == 1) 
                    {
                        LoaderManager.instance.load("CopyGradeBreakText.png", this.onBreakTextLoaded);
                    }
                }
            }
            return;
        }

        /* internal  */set isCommonCopy(arg1: Boolean)
        {
            if (arg1) 
            {
                this._label1.text = Language.getString(60044);
                this._label2.text = Language.getString(60045);
                this._rewardList.visible = false;
                this._getRewardBtn.visible = false;
                this._bestPic.visible = false;
                this._checkBox.visible = true;
            }
            else 
            {
                this._label1.text = Language.getString(27905);
                this._label2.text = Language.getString(27906);
                this._rewardList.visible = true;
                this._getRewardBtn.visible = true;
                this._bestPic.visible = true;
                this._checkBox.visible = false;
            }
            return;
        }

        /* internal  */onTimerEvent(arg1: Object /* flash.events.TimerEvent */): void
        {
            var loc1=null;
            var loc2=this._timer.currentCount;
            switch (loc2) 
            {
                case 1:
                {
                    this._labelNum.label = Language.getString(60046);
                    this._labelNum.updateValue(this._info.num1);
                    this._labelNum.startRoll();
                    break;
                }
                case 2:
                {
                    this._labelExp.label = Language.getString(60047);
                    this._labelExp.updateValue(this._info.num2);
                    this._labelExp.startRoll();
                    break;
                }
                case 3:
                {
                    this._labelTime.label = Language.getString(60048);
                    this._labelTime.updateValue(this._info.num3);
                    this._labelTime.startRoll();
                    break;
                }
                case 4:
                {
                    this._labelProgress.label = Language.getString(60049);
                    this._labelProgress.updateValue(this._info.num4);
                    this._labelProgress.startRoll();
                    break;
                }
                case 5:
                {
                    this._labelRing.label = Language.getString(60050);
                    this._labelRing.updateValue(this._info.num5);
                    this._labelRing.startRoll();
                    break;
                }
                case 6:
                {
                    this._labelCoin.label = Language.getString(60051);
                    this._labelCoin.updateValue(this._info.num7);
                    this._labelCoin.startRoll();
                    break;
                }
                case 7:
                {
                    this._labelScore.label = Language.getString(60052);
                    this._labelScore.updateValue(this._info.num6);
                    this._labelScore.startRoll();
                    break;
                }
                case 8:
                {
                    loc1 = CopyConfig.instance.getCopyGradeInfo(this._info.num6);
                    if (loc1) 
                    {
                        LoaderManager.instance.load("copyGradeLevel_" + loc1.levelString + ".swf", this.onLevelSwfLoaded);
                        if (this._info.num9 == 1) 
                        {
                            LoaderManager.instance.load("CopyGradeBreakText.png", this.onBreakTextLoaded);
                        }
                    }
                    break;
                }
                case this._timer.repeatCount:
                {
                    if (this.copy && this.copy.copyType == ECopyType._ECopyCoin) 
                    {
                        Global.stage.addEventListener(flash.events.MouseEvent.CLICK, this.onStageClick);
                    }
                    else 
                    {
                        this.hide();
                    }
                    break;
                }
            }
            return;
        }

        /* internal  */onStageClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.removeEventListener(flash.events.MouseEvent.CLICK, this.onStageClick);
            this.hide();
            return;
        }

        /* internal  */onLevelSwfLoaded(arg1: SWFInfo): void
        {
            this.removeLevelSwf();
            this._levelSwf = arg1.clip;
            this._levelSwf.x = 330;
            this._levelSwf.y = 112;
            this._levelSwf.play();
            this.addChild(this._levelSwf);
            return;
        }

        /* internal  */checkAndShowBreak(arg1: int, arg2: int): void
        {
            var loc2=null;
            var loc1=Cache.instance.copy.getCopyNumInfoByCode(arg2);
            if (loc1) 
            {
                loc2 = CopyConfig.instance.getCopyGradeInfo(loc1.historyBestCredit);
                if (arg1 > loc2.level) 
                {
                    LoaderManager.instance.load("CopyGradeBreakText.png", this.onBreakTextLoaded);
                }
            }
            return;
        }

        /* internal  */onBreakTextLoaded(arg1: ImageInfo): void
        {
            this.removeBreakText();
            this._textBm = new Object /* flash.display.Bitmap */(arg1.bitmapData);
            this._textBm.x = 222;
            this._textBm.y = 308;
            this.addChild(this._textBm);
            return;
        }

        public reset(): void
        {
            var loc1=0;
            while (loc1 < this._labelVec.length) 
            {
                this._labelVec[loc1].reset();
                ++loc1;
            }
            this._rewardList.dataProvider = new DataProvider([]);
            this.removeLevelSwf();
            this.removeBreakText();
            return;
        }

        public /* override */ hide(): void
        {
            this.reset();
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
            }
            super.hide();
            return;
        }

        /* internal  */removeLevelSwf(): void
        {
            if (this._levelSwf) 
            {
                if (this._levelSwf.parent) 
                {
                    this.removeChild(this._levelSwf);
                }
                this._levelSwf.stop();
                this._levelSwf = null;
            }
            return;
        }

        /* internal */ /* var */_sex: int;

        public /* var */copy: TCopy;

        /* internal */ /* var */_labelNum: CopyGradeRollLabel;

        /* internal */ /* var */_labelExp: CopyGradeRollLabel;

        /* internal */ /* var */_labelTime: CopyGradeRollLabel;

        /* internal */ /* var */_labelProgress: CopyGradeRollLabel;

        /* internal */ /* var */_labelRing: CopyGradeRollLabel;

        /* internal */ /* var */_labelCoin: CopyGradeRollLabel;

        /* internal */ /* var */_labelScore: CopyGradeRollLabel;

        /* internal */ /* var */_labelVec: Vector.<CopyGradeRollLabel>;

        /* internal */ /* var */_levelSwf: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_textBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_closeBtn: GButton;

        /* internal */ /* var */_checkBox: GCheckBox;

        /* internal */ /* var */_label1: GLabel;

        /* internal */ /* var */_label2: GLabel;

        /* internal */ /* var */_rewardList: GTileList;

        /* internal */ /* var */_bestPic: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_getRewardBtn: GButton;

        /* internal */ /* var */_timer: Object /* flash.utils.Timer */;

        /* internal */ /* var */_info: SCopyMsgInfo;
    }
